import java.util.ArrayList;
import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack(){
        this.elem=new int[10];

    }

    public void push(int val){
        if(isFull()){
            //扩容
            elem= Arrays.copyOf(elem, elem.length*2);
        }
        elem[usedSize]=val;
        usedSize++;
    }
    public boolean isFull(){
        return usedSize==elem.length;
    }

    public int pop(){
        if (empty()){
            return -1;
        }
       int oldVal=elem[usedSize-1];
        usedSize--;
        return oldVal;
    }
    public int peek(){
        if (empty()){
            return -1;
        }
        int oldVal=elem[usedSize-1];
//        usedSize--;
//        return oldVal;
        return elem[usedSize-1];
    }
    public boolean empty(){
        return usedSize==0;
    }
}
